<?php

namespace app\models\db;

use Yii;

/**
 * This is the model class for table "t_goods".
 *
 * @property string $id
 * @property string $code
 * @property string $name
 * @property string $display_name
 * @property string $subtitle
 * @property string $short_name
 * @property string $summary
 * @property string $unit
 * @property integer $stock
 * @property string $settlement_price
 * @property string $selling_price
 * @property string $old_price
 * @property string $create_datetime
 * @property string $modify_time
 * @property integer $is_enabled
 * @property integer $is_shelved
 * @property string $shelve_datetime
 * @property integer $is_recommend
 * @property integer $is_newest
 * @property integer $is_hot
 * @property integer $is_free_express
 * @property integer $is_promotion
 * @property integer $is_top
 * @property integer $is_show
 * @property integer $is_audit
 * @property string $audit_datetime
 * @property string $audit_remark
 * @property integer $sell_count
 * @property integer $collected_count
 * @property string $express_money
 * @property integer $is_invoice
 * @property integer $is_GGCT
 * @property integer $is_seven_day
 * @property integer $is_guarantee
 * @property integer $is_return_goods
 * @property string $mini_programs_id
 * @property string $goods_brand_name_id
 * @property integer $sort
 * @property string $e_shop_id
 *
 * @property Cart[] $tCarts
 * @property Favourite[] $tFavourites
 * @property EShop $eShop
 * @property GoodsBrandName $goodsBrandName
 * @property MiniPrograms $miniPrograms
 * @property GoodsCategoryGoods[] $tGoodsCategoryGoods
 * @property GoodsDetailHtml $tGoodsDetailHtml
 * @property GoodsImage[] $tGoodsImages
 * @property OrderGoods[] $tOrderGoods
 */
class Goods extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 't_goods';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'name', 'selling_price', 'mini_programs_id'], 'required'],
            [['stock', 'is_enabled', 'is_shelved', 'is_recommend', 'is_newest', 'is_hot', 'is_free_express', 'is_promotion', 'is_top', 'is_show', 'is_audit', 'sell_count', 'collected_count', 'is_invoice', 'is_GGCT', 'is_seven_day', 'is_guarantee', 'is_return_goods', 'sort'], 'integer'],
            [['settlement_price', 'selling_price', 'old_price', 'express_money'], 'number'],
            [['create_datetime', 'modify_time', 'shelve_datetime', 'audit_datetime'], 'safe'],
            [['id', 'mini_programs_id', 'goods_brand_name_id', 'e_shop_id'], 'string', 'max' => 36],
            [['code', 'name', 'display_name', 'subtitle', 'short_name', 'summary'], 'string', 'max' => 255],
            [['unit'], 'string', 'max' => 100],
            [['audit_remark'], 'string', 'max' => 1024],
            [['e_shop_id'], 'exist', 'skipOnError' => true, 'targetClass' => EShop::className(), 'targetAttribute' => ['e_shop_id' => 'id']],
            [['goods_brand_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => GoodsBrandName::className(), 'targetAttribute' => ['goods_brand_name_id' => 'id']],
            [['mini_programs_id'], 'exist', 'skipOnError' => true, 'targetClass' => MiniPrograms::className(), 'targetAttribute' => ['mini_programs_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'code' => 'Code',
            'name' => 'Name',
            'display_name' => 'Display Name',
            'subtitle' => 'Subtitle',
            'short_name' => 'Short Name',
            'summary' => 'Summary',
            'unit' => 'Unit',
            'stock' => 'Stock',
            'settlement_price' => 'Settlement Price',
            'selling_price' => 'Selling Price',
            'old_price' => 'Old Price',
            'create_datetime' => 'Create Datetime',
            'modify_time' => 'Modify Time',
            'is_enabled' => 'Is Enabled',
            'is_shelved' => 'Is Shelved',
            'shelve_datetime' => 'Shelve Datetime',
            'is_recommend' => 'Is Recommend',
            'is_newest' => 'Is Newest',
            'is_hot' => 'Is Hot',
            'is_free_express' => 'Is Free Express',
            'is_promotion' => 'Is Promotion',
            'is_top' => 'Is Top',
            'is_show' => 'Is Show',
            'is_audit' => 'Is Audit',
            'audit_datetime' => 'Audit Datetime',
            'audit_remark' => 'Audit Remark',
            'sell_count' => 'Sell Count',
            'collected_count' => 'Collected Count',
            'express_money' => 'Express Money',
            'is_invoice' => 'Is Invoice',
            'is_GGCT' => 'Is  Ggct',
            'is_seven_day' => 'Is Seven Day',
            'is_guarantee' => 'Is Guarantee',
            'is_return_goods' => 'Is Return Goods',
            'mini_programs_id' => 'Mini Programs ID',
            'goods_brand_name_id' => 'Goods Brand Name ID',
            'sort' => 'Sort',
            'e_shop_id' => 'E Shop ID',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTCarts()
    {
        return $this->hasMany(Cart::className(), ['good_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTFavourites()
    {
        return $this->hasMany(Favourite::className(), ['good_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEShop()
    {
        return $this->hasOne(EShop::className(), ['id' => 'e_shop_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGoodsBrandName()
    {
        return $this->hasOne(GoodsBrandName::className(), ['id' => 'goods_brand_name_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMiniPrograms()
    {
        return $this->hasOne(MiniPrograms::className(), ['id' => 'mini_programs_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTGoodsCategoryGoods()
    {
        return $this->hasMany(GoodsCategoryGoods::className(), ['goods_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTGoodsDetailHtml()
    {
        return $this->hasOne(GoodsDetailHtml::className(), ['goods_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTGoodsImages()
    {
        return $this->hasMany(GoodsImage::className(), ['goods_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTOrderGoods()
    {
        return $this->hasMany(OrderGoods::className(), ['goods_id' => 'id']);
    }
}
